package com.dinzeer.sjapadder.se;

import com.dinzeer.legendreliclib.lib.util.FastMakeEntityUtil;
import com.dinzeer.legendreliclib.lib.util.slashblade.SlashBladeUtil;
import com.dinzeer.sjapadder.register.SjaEffect;
import com.dinzeer.sjapadder.register.SjaSpecialEffectRegsitry;
import mods.flammpfeil.slashblade.capability.slashblade.ISlashBladeState;
import mods.flammpfeil.slashblade.event.SlashBladeEvent;
import mods.flammpfeil.slashblade.registry.specialeffects.SpecialEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.AABB;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import java.util.List;

@Mod.EventBusSubscriber
public class FateBond extends SpecialEffect {


    public FateBond() {
        super(30);
    }

    @SubscribeEvent
    public static void SlashBladeUpdate(SlashBladeEvent.UpdateEvent event){
        ISlashBladeState state= event.getSlashBladeState();
        if (event.getEntity() instanceof Player player){
            if (state.hasSpecialEffect(SjaSpecialEffectRegsitry.FateBond.getId())){
                if (event.isSelected()){
            if (SpecialEffect.isEffective(SjaSpecialEffectRegsitry.FateBond.getId(), player.experienceLevel)){
                player.heal(0.1f);
                FastMakeEntityUtil.FastEffect(player, MobEffects.DAMAGE_BOOST, 3);
                FastMakeEntityUtil.FastEffect(player, MobEffects.MOVEMENT_SPEED, 3);
                FastMakeEntityUtil.FastEffect(player, MobEffects.DAMAGE_RESISTANCE, 3);
                FastMakeEntityUtil.FastEffect(player, MobEffects.JUMP, 3);




                AABB area = new AABB(
                        player.getX() - 8, player.getY() - 8, player.getZ() - 8,
                        player.getX() + 8, player.getY() + 8, player.getZ() + 8
                );

                List<LivingEntity> nearbyEntities = player.level().getEntitiesOfClass(
                        LivingEntity.class, area, e -> e != player &&
                                (e instanceof Player || e.isAlliedTo(player) || player.isAlliedTo(e))
                );

                // 给附近友方实体添加抗性提升效果
                for (LivingEntity ally : nearbyEntities) {
                    ally.addEffect(new MobEffectInstance(
                            SjaEffect.Tranquility.get(), // 抗性提升效果
                            200, // 持续时间（10秒，20 ticks/秒）
                            0, // 等级（0 = I级）
                            false, // 环境粒子效果
                            true // 显示图标
                    ));
                }










            }
                }
            }
        }
    }








}
